/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.17
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   选择指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "selectinstructionview.h"
#include "ui_selectinstructionview.h"
#include "../../programView/programview.h"


SelectInstructionView::SelectInstructionView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::SelectInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
}

void SelectInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void SelectInstructionView::updateView()
{
    ui->R_lineEdit->setText(rValue);
    ui->RIndex_lineEdit->setText(rIndex);
    ui->lblIndex_lineEdit->setText(lblIndex);

    if(0 == dealWithType)
    {
        ui->JMP_radioButton->setChecked(true);
    }
    else
    {
        ui->CALL_radioButton->setChecked(true);
    }

    ui->CALL_lineEdit->setText(callProgram);
    ui->note_lineEdit->setText(note);
}

void SelectInstructionView::getInput()
{
    rIndex = ui->RIndex_lineEdit->text();
    rValue = ui->R_lineEdit->text();
    lblIndex = ui->lblIndex_lineEdit->text();
    callProgram = ui->CALL_lineEdit->text();
    note = ui->note_lineEdit->text();
}

void SelectInstructionView::on_JMP_radioButton_clicked()
{
    emit selectJmpDeal();
}

void SelectInstructionView::on_CALL_radioButton_clicked()
{
    emit selectCallDeal();
}

void SelectInstructionView::on_browse_Btn_clicked()
{
    emit browseCallProgram(callLocation);
}

void SelectInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNote();
}

void SelectInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void SelectInstructionView::on_save_Btn_clicked()
{
    getInput();

    emit finishEditInstruction();
    emit saveInstruction(selectInstruction);
}

void SelectInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/selectViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}
